#Alexander F. Gazmararian
#afg2@princeton.edu

# Load packages
library(tidyverse)
library(lmtest)
library(sandwich)
library(modelsummary)
library(kableExtra)
library(broom)

source("code/fun/fix_txt.r")

#specify baseline model
source("code/fun/model_spec.r")

#adjust baseline model for youth sample
f.base <- update(f.base, ~ . + pc1 + youth_block - CollegeDegree + HighestEd + mobility_f)

#load coefficient names
source("code/fun/coefnames4tables.r")
coefnames <- c("budget_conditionsmall"="Small Budget Treatment", coefnames)

#load data
g <- readRDS("data/NatYouthQual.rds")

#estimate models
m <- list()
m[[1]] <- lm(budget_reduce ~ budget_condition, g)
m[[2]] <- lm(update(f.base, budget_reduce ~ budget_condition + .), g)

# create table
file <- "tables/ch7/ols_budgetfollow.txt"
modelsummary(
  m,
  vcov = "HC2",
  stars = c("*"=.1,"**"=.05,"***"=.01),
  coef_map = coefnames,
  coef_omit = "Income",
  output = "latex",
  escape = TRUE,
  gof_map = c("nobs", "adj.r.squared")
) %>%
  cat(., file = file)
fix_txt(file)
